package cn.itlaobing.eshopmanagement.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import cn.itlaobing.eshopmanagement.entity.Activity;
import cn.itlaobing.eshopmanagement.mapper.ActivityMapper;
import cn.itlaobing.eshopmanagement.service.ActivityService;

@Service
public class ActivityServiceImpl implements ActivityService {
	Log log = LogFactory.getLog(this.getClass());
	@Autowired
	private ActivityMapper activityMapper;

	// 分页显示活动内容，根据或动名称搜索或动内容
	@Override
	public List<Activity> findBySearchFilter(Map<String, String> searchFilter) {
		if (searchFilter == null) {
			searchFilter = new HashMap<>();
		}
		if (StringUtils.isBlank(searchFilter.get("pageNum"))) {
			searchFilter.put("pageNum", "1");
		}
		if (StringUtils.isBlank(searchFilter.get("pageSize"))) {
			searchFilter.put("pageSize", "3");
		}

		PageHelper.startPage(searchFilter);
		return activityMapper.findBySearchFilter(searchFilter);
	}

	// 根据id查找活动内容
	@Override
	public Activity findbyId(long id) {

		return activityMapper.selectByPrimaryKey(id);
	}

	// 添加活动内容
	@Override
	public long save(Activity activity) {

		return activityMapper.insert(activity);
	}

	// 删除活动内容
	@Override
	public void delete(long id) {

		activityMapper.deleteByPrimaryKey(id);
	}

}
